﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;

namespace Wicresoft.EKA.NRemedy.Linq
{
    public class TranslateResult
    {
        public enum Operation { where, select, orderby, orderbydescending, groupby, statisticnocount }

        public StringBuilder Qulification { get; set; }

        public string StatisticNoCountExpresion;

        public Operation CurrentOpeation { get; set; }

        public List<uint> SelectIds { get; set; }

        public List<int> OrderIds { get; set; }

        public List<int> GroupIds { get; set; }

        public int? Take = null;

        public int? Skip = null;

        public Type TargetType { get; set; }

        public LambdaExpression SelectExpression { get; set; }

        public bool Count { get; set; }

        //1 = Count, 2 = Sum, 3 = Average, 4 = Minimum, 5 = Maximum 
        public uint StatisticStatusCode { get; set; }

        public TranslateResult()
        {
            Qulification = new StringBuilder();
            SelectIds = new List<uint>();
            OrderIds = new List<int>();
            GroupIds = new List<int>();
        }

        public void AddDescription(string op)
        {
            switch (CurrentOpeation)
            {
                case Operation.where:
                    Qulification.Append(op);
                    break;
                case Operation.orderby:
                case Operation.orderbydescending:
                    OrderIds.Add(int.Parse(op));
                    break;
                case Operation.select:
                    SelectIds.Add(uint.Parse(op));
                    break;
                case Operation.groupby:
                    GroupIds.Add(int.Parse(op));
                    break;
                case Operation.statisticnocount:
                    StatisticNoCountExpresion = op;
                    break;
                default:
                    break;
            }
        }
    }
}
